package network;


import java.util.HashMap;

import org.apache.log4j.Logger;

import interfaces.INetwork;
import mediator.Mediator;

public class Network implements INetwork {

	Mediator med;
	HashMap<Integer, TransportTask> workers;
	
	public static Logger logger = Logger.getLogger(Network.class);
	
	public Network(Mediator m) {
		med = m;	
		workers = new HashMap<>();
	}
	
	@Override
	public void transfer(int row) {
		logger.info("Transfer started");
		
		TransportTask tt = new TransportTask();

		MyPropertyChangeListener mpcl = new MyPropertyChangeListener(med, row);

		tt.addPropertyChangeListener(mpcl);
		tt.execute();
		workers.put(row, tt);
	}

	@Override
	public void transferFailed(int row) {
		workers.get(row).cancel(true);
		workers.get(row).done();
		med.transferFailed(row);
		
	}
	
	

}
